package interview.multithread;

public class ImplementRunnable {
    public static void main(String[] args) {

        MyRunnable myRunnable = new MyRunnable();
        new Thread(myRunnable).start();
        new Thread(myRunnable).start();
        new Thread(myRunnable).start();
    }
}

class MyRunnable implements Runnable{
    private int ticket = 5;

    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
//            synchronized (this){
            if (ticket > 0) {
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                    System.out.println(Thread.currentThread().getName()+"-车票第"+ticket--+"张");
                }
//            }
        }
    }
}